var handle = {};
var formidable = require("formidable");
 
handle["/"] = start;
handle["/start"] = start;
handle["/upload"] = upload;
 
function start(request, response) {
  var body = '<html>'+
    '<head>'+
    '<meta http-equiv="Content-Type" content="text/html; '+
    'charset=UTF-8" />'+
    '</head>'+
    '<body>'+
    '<form action="/upload" method="post">'+
    '学号：<input type="text" name="id" /><br /><br />'+
    '姓名：<input type="text" name="name" /><br /><br />'+
    '<input type="submit" value="提交" />'+
    '</form>'+
    '</body>'+
    '</html>';
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write(body);
    response.end();
}
 
function upload(request, response) {
    var form = new formidable.IncomingForm();
    form.parse(request, function(error, fields, files) {
    console.log("id:" + fields.id);
    console.log("name:" + fields.name);
    response.writeHead(200, {"Content-Type": "text/html;charset=utf-8"});
    response.write("id:" + fields.id + "<br>");
    response.write("name:" + fields.name);
    response.end();
    });
}
 
exports.handle = handle;
exports.start = start;
exports.upload = upload;